<?php
class ReligionsController extends AppController {

	var $name = 'Religions';
	var $helpers = array('Html', 'Form');

    function index_admin() 
    {
        if($this->Session->read('User.type')=='admin')
        {
            $this->layout = 'ajax';
            if(!empty($this->data))
            { 
                if($this->data['Religion']['name'] == '' )
                {
                    $this->set('empty',true);
                }
                else                
                if(!empty($this->data['Religion']['id']))
                {
                    $count = $this->Religion->find('count',array('conditions'=>array('Religion.name'=>$this->data['Religion']['name'],'Religion.id <>'=>$this->data['Religion']['id'])));
                    if( $count == 0 ) 
                    { $this->Religion->save($this->data); }
                    else
                    { $this->set('wrong',true); } 
                }
                else
                {
                    $count = $this->Religion->find('count',array('conditions'=>array('Religion.name'=>$this->data['Religion']['name'])));
                    if( $count == 0 ) 
                    { 
                        $this->Religion->create(); 
                        $this->Religion->save($this->data); 
                    }                
                    else
                    { $this->set('wrong',true); }
                }
            }
            $this->Religion->recursive=-1;
            $religions = $this->Religion->find('all',array('order'=>'Religion.id'));
            $this->set('religions',$religions);
        }     
    }
                    
    function delete_admin($id)
    {  
        if($this->Session->read('User.type')=='admin')
        {
            $this->layout = 'ajax';
            $this->Religion->del($id);
            $this->redirect(array('controller'=>'religions','action'=>'index_admin'));
        }        
    }    

}
?>